
	
use Data/Estimation_sample.dta, clear
	
	gen nexis_buildings  = ROOFME/PROOFME
		
		
	gen roofratio = ROOFME/ROOFTI
	gen roofratiobuildings = roofratio*nexis_buildings
		
	gen roofrelativeIV = (roofratio*nexis_buildings/[moduleprice])/1000

	

	
* 3 quarters is nine months, total of 28 quarters in sample
local length = 4
	 
forval t = 0(1)`length' {
	gen event_after`t' =  SHCP_end ==`t' |  PFIT_starttime==`t' | PFIT_endtime==`t' | ///
	 SRES1_end ==`t' | SRES2_end==`t' | SRES_TFIT_endtime==`t' | FFIT_endtime==`t'
	 
	 
	 gen event_before`t' =  SHCP_end ==-`t'  | PFIT_starttime==-`t' | PFIT_endtime==-`t' | ///
	 SRES1_end ==-`t' | SRES2_end==-`t' | SRES_TFIT_endtime==-`t' | FFIT_endtime==-`t'
	
	gen event_after_new`t' = event_after`t'*cum
	gen event_before_new`t' = event_before`t'*cum
	
	gen event_after_high`t' = event_after`t'*roofrelativeIV
	gen event_before_high`t' = event_before`t'*roofrelativeIV
	
	drop event_after`t'
	drop event_before`t'
	
	
	
	}
		
	
* reference time 
drop  event_after_high0  event_after_new0 // event_before_high1 event_before_new1

label variable event_before_new4  "Event Period -4"
label variable event_before_new3  "Event Period -3"
label variable event_before_new2  "Event Period -2"
label variable event_before_new1  "Event Period -1"
label variable event_before_new0  "Event Period "
label variable event_after_new1   "Event Period +1"
label variable event_after_new2   "Event Period +2"
label variable event_after_new3   "Event Period +3"
label variable event_after_new4   "Event Period +4"




xi: xtivreg2 green_p event_before_new4 event_before_new3 event_before_new2 event_before_new1 event_before_new0 ///
event_after_new1  event_after_new2 event_after_new3 event_after_new4  i.quarter   [aweight=NCustomer]  , fe cluster(postcode)



	summ green_plan [aweight =NCust	] if e(sample)
    local meandepvar=round(`r(mean)',.001)


 outreg2 using Analysis/Motivation_quarterly_year, bdec(3) se  nocons label  ctitle("FE")   ///
	keep(event* cum mean_weighted TotalHouse_interp quarter ) addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, `meandepvar')  tex(fragment pretty) nonotes replace

estimates save Analysis/Motivation_year, replace





xi:  xtivreg2 green_p (event_before_new4 event_before_new3 event_before_new2 event_before_new1 event_before_new0 event_after_new1  ///
event_after_new2 event_after_new3 event_after_new4   = event_after_high* event_before_high* )  i.quarter  [aweight=NCustomer]   , ffirst fe cluster(postcode)



	summ green_plan [aweight =NCust	] if e(sample)
    local meandepvar=round(`r(mean)',.001)


 outreg2 using Analysis/Motivation_quarterly_year, bdec(3) se  nocons label  ctitle("IV")  ///
	keep(event* cum mean_weighted TotalHouse_interp quarter ) addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, `meandepvar')  tex(fragment pretty) nonotes append


estimates save Analysis/Motivation_yearIV, replace
